﻿package desk.game.eatbean;

import javax.microedition.lcdui.Graphics;

public class Enemy {
	private int x,y;
	private int p=999;
	private int width,height;
	private boolean open=true;
	static int speed=5;
	public Enemy(){}
	public Enemy(int x,int y,int width,int height)
	{
		this.x=x;
		this.y=y;
		this.width=width;
		this.height=height;
	}
	protected void paint(Graphics g) {
		open=!open;
		g.setColor(0, 0, 255);
		if(p==6)
		{
			x=x+speed;
			if(open==true)
				g.fillArc(x, y, 20, 20, 0, 360);
			else
				g.fillArc(x, y, 20, 20, 15, 310);
		}
		if(p==4)
		{
			x=x-speed;
			if(open==true)
				g.fillArc(x, y, 20, 20, 0, 360);
			else
				g.fillArc(x, y, 20, 20, 205, 310);
		}
		if(p==2)
		{
			y=y-speed;
			if(open==true)
				g.fillArc(x, y, 20, 20, 0, 360);	
			else
				g.fillArc(x, y, 20, 20, 115, 310);
		}
		if(p==8)
		{
			y=y+speed;
			if(open==true)
				g.fillArc(x, y, 20, 20, 0, 360);	
			else
				g.fillArc(x, y, 20, 20, 295, 310);
		}				
	}
	protected void run(int x,int y)
	{
		if(Math.abs(this.x-x)>Math.abs(this.y-y))
			{
				if(this.x>x)
					p=4;
				else
					p=6;
			}
		else
			{
				if(this.y>y)
					p=2;
				else
					p=8;
			}
		if(Math.abs(this.x-x)<10 && Math.abs(this.y-y)<10)
		{
			p=0;
		}
	}
	public void drawFail(Graphics g) 
	{
		if(p==0)
		{
			g.setColor(255,255,255);
			g.drawString("you lost!",width/2,height/2,Graphics.BASELINE|Graphics.HCENTER);
		}
	}
	public int getP()
	{
		return p;
	}
	public void setSpeed()
	{
		speed++;
	}
	public int getSpeed()
	{
		return speed;
	}
}
